home *** CD-ROM | disk | FTP | other *** search
/ USA Bestseller / USA BESTSELLER Vol 1-95 (Hepp-Computer)(1995).iso / e193 / 0150ter2._xe / PASCAL.EXE / LSTPHONE.PAS < prev    next >
Pascal/Delphi Source File  |  1994-07-22  |  1KB  |  47 lines

  1. Program ListPhoneBook;
  2.  
  3. { A small Terminate utility to show how to use the phonebook }
  4.  
  5. {$I PHONE.100}
  6.  
  7. Var
  8.   PhoneFile : File;
  9.   x         : Word;
  10.  
  11. Procedure FatalError(s:string);
  12. Begin
  13.   WriteLn('Fatal: '+s+#10#10);
  14.   Halt;
  15. End;
  16.  
  17. Begin
  18.  
  19.   FillChar(PHead,Sizeof(PHead),0);
  20.   Assign(PhoneFile,'TERMINAT.FON');
  21.   {$I-} Reset(PhoneFile,1); {$I+}
  22.   If IOResult=0 Then
  23.   Begin
  24.  
  25.     { Read the header in the phone file }
  26.     {$I-} BlockRead(PhoneFile,PHead,Sizeof(PHead)); {$I+}
  27.     If IOResult<>0 Then FatalError('Error in start of phonebook');
  28.  
  29.     { Read all records into structure }
  30.     For x:=1 to PHead.Num Do
  31.     Begin
  32.       New(Ph[x]); { Reserve memory }
  33.       {$I-} BlockRead(PhoneFile,Ph[x]^.P,Sizeof(Ph[x]^.P)); {$I+}
  34.       If IOResult<>0 Then FatalError('Error in phonebook, maybe wrong version');
  35.     End;
  36.  
  37.     Close(PhoneFile);
  38.   End;
  39.  
  40.   { Write all phonenumbers on screen }
  41.   For x:=1 to PHead.Num Do WriteLn(Ph[x]^.P.Name);
  42.  
  43.   { Free memory before exiting }
  44.   For x:=1 to PHead.Num Do Dispose(Ph[x]);
  45.  
  46. End.
  47.